function [event_clock,alg]=maintain(event_clock,alg)


global NUMBER_OF_EVENTS LENGTH BIG TNOW MAINT_COST REPAIR_COST SALES_REVENUE EXP_RATE 
global SHAPE1 SCALE1 SHAPE2 SCALE2 A3 B3 B U L MU STATES_MAX 
% A maintenance has just been completed 

event_clock(4)=BIG; % first wipe out the time of the current event



alg.revenue=alg.revenue-MAINT_COST;
alg.old_action=2;
[alg]=rac(alg); 
alg.prodcount=0;
alg.old_prodcount=alg.prodcount;
alg.time_for_failure=gamrnd(SHAPE1,SCALE1);
event_clock(2)=TNOW+0.1; % schedule a new production


